package com.example.woke;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.http.HttpMethods;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.PersistentCookieStore;
import com.loopj.android.http.RequestParams;
import com.woke.method.Intentnet;
import com.zhongcai.online.R;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Zcailist_infoActivity extends Activity {

	private TextView mTtype,mTother,mTid,mTtime;
	private RelativeLayout mBar;
	private String id;
	private TextView mTmoney,mTname;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zcailist_info);
		
		id = getIntent().getStringExtra("id");
		intview();
		
	}

	private void intview() {
		mTtype = (TextView) findViewById(R.id.avzcailistinfo_text_type);
		mTother = (TextView) findViewById(R.id.avzcailistinfo_text_ohter);
		mTid = (TextView) findViewById(R.id.avzcailistinfo_text_orderid);
		mTtime = (TextView) findViewById(R.id.avzcailistinfo_text_time);
		mBar = (RelativeLayout) findViewById(R.id.avzcailistinfo_progress);
		mTmoney = (TextView) findViewById(R.id.avzcailistinfo_text_money);
		mTname = (TextView) findViewById(R.id.avzcailistinfo_text_name);
		findViewById(R.id.avzcailistinfo_image_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		getlistinfo();
	}

	private void getlistinfo() {
		AsyncHttpClient ahc = new AsyncHttpClient();
		PersistentCookieStore myCookieStore = new PersistentCookieStore(
				Zcailist_infoActivity.this);
		ahc.setCookieStore(myCookieStore);
		RequestParams params = new RequestParams();
		params.put("g", "api");
		params.put("m", "user");
		params.put("a", "moneyLog");
		params.put("id", id+"");
		Log.e("getlistinfo+params",params.toString());
		Log.e("getlistinfo+url",HttpMethods.BASEURL);
		ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler() {
			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess(statusCode, headers, response);
			Log.e("getlistinfo+response",response.toString());
				try {
					String flag = response.getString("flag");
					if (flag.equals("success")) {
						JSONObject jsonObject = response.getJSONObject("data");
						JSONArray data = jsonObject.getJSONArray("data");
						JSONObject object=data.getJSONObject(0);
						String create_time = object.getString("create_time");
							mTtime.setText(Intentnet.getStrTi(create_time));
							String money = object.getString("money");
							String id = object.getString("id");
							String trade_no = object.getString("trade_no");
							mTid.setText(trade_no);
							String type = object.getString("type");
							
							if(type.equals("1")){
								mTtype.setText("充值");
							}else if(type.equals("2")){
								mTtype.setText("提现");
							}else if(type.equals("12")){
								mTtype.setText("会员升级");
							}else if(type.equals("11")){
								mTtype.setText("管理员增金");
							}else if(type.equals("3")){
								mTtype.setText("中财借贷");
							}else if(type.equals("4")){
								mTtype.setText("中财理财");
							}else if(type.equals("5")){
								mTtype.setText("中财支付");
							}else if(type.equals("6")){
								mTtype.setText("财信通");
							}else if(type.equals("7")){
								mTtype.setText("转账");
							}else if(type.equals("71")){
								mTtype.setText("管理员转账");
							}else if(type.equals("8")){
								mTtype.setText("中财众筹");
							}else if(type.equals("9")){
								mTtype.setText("收益");
							}else if(type.equals("91")){
								mTtype.setText("理财收益");
							}else if(type.equals("92")){
								mTtype.setText("下线升级");
							}else if(type.equals("93")){
								mTtype.setText("邀请下线");
							}else if(type.equals("41")){
								mTtype.setText("中财活期理财");
							}else if(type.equals("42")){
								mTtype.setText("中财定期理财");
							}else if (type.equals ("94")) {
								mTname.setText ("下级分润");
							} else if(type.equals ("51")){
								mTname.setText ("提现直清");
							} else if(type.equals ("52")){
								mTname.setText ("代还充值");
							} else if(type.equals ("53")){
								mTname.setText ("代还提现");
							} else if(type.equals ("95")){
								mTname.setText ("彩票分润");
							}else if(type.equals ("100")){
								mTname.setText ("购买彩票");
							}else if(type.equals ("101")){
								mTname.setText ("彩票退款");
							}else if(type.equals ("102")){
								mTname.setText ("彩票中奖");
							}
							
							String status = object.getString("status");
							if(status.equals("1")){
								mTmoney.setText("-"+money);
								mTname.setText("出账金额");
							}else{
								mTmoney.setText("+"+money);
								mTname.setText("入账金额");
							}
							String note = object.getString("note");
							mTother.setText(note);
							
					} else if (flag.equals("unknow")) {
						String info = response.getString("info");
						Toast.makeText(Zcailist_infoActivity.this, info,Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
				
				
			}

			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure(statusCode, headers, responseString, throwable);
				Toast.makeText(Zcailist_infoActivity.this, "数据失败！",
						Toast.LENGTH_SHORT).show();
				Log.e("借给他是吧dd", "失败" + responseString);
			}

			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				super.onStart();
				
				mBar.setVisibility(View.VISIBLE);
				
			}

			@Override
			public void onFinish() {
				super.onFinish();
				mBar.setVisibility(View.GONE);
//				Log.e("������ǰ�", "���");
			}
		});
	}
}
